<?php
require '../config.php';
$query="select idcategoriasclientes,descripcion from categoriasclientes";
$result = mysql_query("select nombre from roles  where idroles= '". $_SESSION['rol'] ."'",$conexion);
if(mysql_num_rows($result)>0)
{
	$row = mysql_fetch_assoc($result);
	if($row['nombre']== "OPERADOR" or $row['nombre']== "Super_Operadores" )
		$query="select idcategoriasclientes,descripcion from categoriasclientes where descripcion != 'RECURRENTE'";
}

$registros=mysql_query($query,$conexion) or die("Problemas en el select:".mysql_error());
if (mysql_num_rows($registros) == 0)
{
	echo "0";
}
else
{
	$data = array();
	while ($row = mysql_fetch_array($registros)) {
		$data[] = $row['idcategoriasclientes'];
		$data[] = _convert($row['descripcion']);
		 
	}
		
	echo json_encode($data);
}
function _convert($content) {
	if(!mb_check_encoding($content, 'UTF-8')
	OR !($content === mb_convert_encoding(mb_convert_encoding($content, 'UTF-32', 'UTF-8' ), 'UTF-8', 'UTF-32'))) {

		$content = mb_convert_encoding($content, 'UTF-8');

		if (mb_check_encoding($content, 'UTF-8')) {
			// log('Converted to UTF-8');
		} else {
			// log('Could not converted to UTF-8');
		}
	}
	return $content;
}
mysql_close($conexion);
?>